package com.itheima.binarysearch;

public class BinarySearchAlter {
    public static void main(String[] args) {
        int[] arr = {3,6,7,9,10,15,19,28,31,40};
        System.out.println(binarySearch(arr, 40));
    }

    public static int binarySearch(int[] arr, int target) {
        int i = 0, j = arr.length;

        while (i < j) {
            int m = (i + j) >>> 1;
            if (target < arr[m]) {
                j = m;
            }else if (arr[m] < target){
                i = m + 1;
            }else {
                return m;
            }
        }
        return -1;
    }
}
